package org.linlinjava.litemall.admin.web2.goods.req;

import io.swagger.annotations.ApiModel;
import io.swagger.annotations.ApiModelProperty;
import org.linlinjava.litemall.core.util.Util;
import org.linlinjava.litemall.db.domain.TGoods;
import org.linlinjava.litemall.db.enumeration.Const;
import org.linlinjava.litemall.db.util.Str;

import java.math.BigDecimal;
import java.time.LocalDateTime;
import java.time.format.DateTimeFormatter;

@ApiModel
public class GReq1 {

    @ApiModelProperty("商品id")
    private Integer id;
    @ApiModelProperty("分类id")
    private Integer cId;
    @ApiModelProperty("商品主标题")
    private String mainTitle;
    @ApiModelProperty("商品次标题")
    private String subTitle;
    @ApiModelProperty("成本价")
    private String costPrice;
    @ApiModelProperty("市场售价")
    private String salePrice;
    @ApiModelProperty("当前销售价")
    private String currentPrice;
    @ApiModelProperty("每日库存")
    private Integer dailyLimit;
    @ApiModelProperty("商品主图")
    private String mainPic;
    @ApiModelProperty("商品图片2")
    private String pic2;
    @ApiModelProperty("商品图片3")
    private String pic3;
    @ApiModelProperty("商品视频")
    private String mainVedio;
    @ApiModelProperty("上架方式:[0-立即上架、1-定时预售、2-放入仓库")
    private Integer upperType;
    @ApiModelProperty("预售时间,格式[yyyy-MM-dd HH:mm")
    private String saleTime;
    @ApiModelProperty("商品详情")
    private String detail;


    public static TGoods getTGoods(GReq1 req) {
        TGoods goods = TGoods.builder().cId(req.getcId()).mainTitle(req.getMainTitle()).subTitle(req.getSubTitle())
                .costPrice(new BigDecimal(req.getCostPrice()))
                .salePrice(new BigDecimal(req.getSalePrice()))
                .currentPrice(new BigDecimal(req.getCurrentPrice()))
                .dailyLimit(req.getDailyLimit())
                .mainPic(req.getMainPic())
                .pic2(req.getPic2())
                .pic3(req.getPic3())
                .mainVedio(req.getMainVedio())
                .status(req.getUpperType())
                .shopId(0)  //默认平台
                .type(Const.GOODS_TYPE.NONE)
                .deleted(Boolean.FALSE)
                .detail(req.getDetail()).build();
        if (!Str.isEmpty(req.getSaleTime())) {
            goods.setSaleTime(LocalDateTime.parse(req.getSaleTime(), DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm")));
        }
        return goods;
    }

    public static GReq1 getDTO(TGoods entity) {
        GReq1 req = new GReq1();
        Util.copy(entity, req);
        req.setCostPrice(entity.getCostPrice().toString());
        req.setSalePrice(entity.getSalePrice().toString());
        req.setCurrentPrice(entity.getCurrentPrice().toPlainString());
        req.setUpperType(entity.getStatus());
        req.setSaleTime(entity.getSaleTime() == null ? null : entity.getSaleTime().toString());
        return req;
    }

    public Integer getId() {
        return id;
    }

    public void setId(Integer id) {
        this.id = id;
    }

    public Integer getcId() {
        return cId;
    }

    public void setcId(Integer cId) {
        this.cId = cId;
    }

    public String getMainTitle() {
        return mainTitle;
    }

    public void setMainTitle(String mainTitle) {
        this.mainTitle = mainTitle;
    }

    public String getSubTitle() {
        return subTitle;
    }

    public void setSubTitle(String subTitle) {
        this.subTitle = subTitle;
    }

    public String getCostPrice() {
        return costPrice;
    }

    public void setCostPrice(String costPrice) {
        this.costPrice = costPrice;
    }

    public String getSalePrice() {
        return salePrice;
    }

    public void setSalePrice(String salePrice) {
        this.salePrice = salePrice;
    }

    public String getCurrentPrice() {
        return currentPrice;
    }

    public void setCurrentPrice(String currentPrice) {
        this.currentPrice = currentPrice;
    }

    public Integer getDailyLimit() {
        return dailyLimit;
    }

    public void setDailyLimit(Integer dailyLimit) {
        this.dailyLimit = dailyLimit;
    }

    public String getMainPic() {
        return mainPic;
    }

    public void setMainPic(String mainPic) {
        this.mainPic = mainPic;
    }

    public String getPic2() {
        return pic2;
    }

    public void setPic2(String pic2) {
        this.pic2 = pic2;
    }

    public String getPic3() {
        return pic3;
    }

    public void setPic3(String pic3) {
        this.pic3 = pic3;
    }

    public String getMainVedio() {
        return mainVedio;
    }

    public void setMainVedio(String mainVedio) {
        this.mainVedio = mainVedio;
    }

    public Integer getUpperType() {
        return upperType;
    }

    public void setUpperType(Integer upperType) {
        this.upperType = upperType;
    }

    public String getSaleTime() {
        return saleTime;
    }

    public void setSaleTime(String saleTime) {
        this.saleTime = saleTime;
    }

    public String getDetail() {
        return detail;
    }

    public void setDetail(String detail) {
        this.detail = detail;
    }
}
